// VS_BEGIN
#version 330 core
layout (location = 0) in vec3 aPos;

layout (std140) uniform EngineUBO
{
    mat4 u_view;
    mat4 u_project;
    vec3 u_camPos;
};

out vec3 g_texCoord;

void main() {
    g_texCoord = aPos;
    gl_Position = u_project * mat4(mat3(u_view)) * vec4(aPos, 1.0f);
}
// VS_END

// FS_BEGIN
#version 330 core

uniform sampler2D u_irradianceMap;

in vec3 g_texCoord;

out vec4 FragColor;

const vec2 invAtan = vec2(0.1591, 0.3183);
vec2 SampleSphericalMap(vec3 v)
{
    vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
    uv *= invAtan;
    uv += 0.5;
    return uv;
}

void main() {
    vec2 uv = SampleSphericalMap(normalize(g_texCoord)); // make sure to normalize localPos
    vec3 color = texture(u_irradianceMap, uv).rgb;
    FragColor = vec4(color, 1.0);
}
// FS_END